package cell;

import java.util.Random;

public class Cell {
	
	private static long instanceId;

	private long id;
	
	private int divideTimes = 4;
	
	private int telomeroLength;

	private Environment environment;
	
	// Constructor
	public Cell(Environment env) {
		super();
		this.environment = env;
		instanceId++;
		id = instanceId;
	}

	public void run() {
		Random random = new Random();

        System.out.println(id + "- run");
        
        if( random.nextInt() < 10 
        		&& divideTimes > 0 
        		&& telomeroLength > 0 )
        {
        	divideTimes--;
        	mitosis();
        }
	}

	private void mitosis() {
		System.out.println(id + "- Mitosis");
		Cell cell = new Cell( environment );
		cell.setTelomeroLength( telomeroLength - 1 );
		environment.add(cell);
	}

	public void setTelomeroLength(int telomeroLength) {
		this.telomeroLength = telomeroLength;
	}

	public int getTelomeroLength() {
		return telomeroLength;
	}
	
	
}
